<?php 
	include '../init.php';
	
	//判断是否进行编辑
	if (!empty($_GET['id'])) {
		$id=$_GET['id'];
		$sql="SELECT * FROM category WHERE id={$id}";
		$row = $mysql -> getRow($sql);
	}

	if (isset($row['pid'])) {
		//进入编辑的表单分类情况
		$categoryForm=getCategoryForm($row['pid']);
	}else{
		//进入增加分类的情况
		$categoryForm=getCategoryForm();
	}

?>
<!DOCTYPE html>
<html>
<head>
	<title>添加分类</title>
	<meta charset="utf-8">
	<link rel="stylesheet" type="text/css" href="<?php echo __PUBLIC__;?>/bootsrap/css/bootstrap.min.css">
	<script type="text/javascript" src="<?php echo __PUBLIC__;?>/js/jquery.js"></script>
	<script type="text/javascript" src="<?php echo __PUBLIC__;?>/bootsrap/js/bootstrap.min.js"></script>
	<script type="text/javascript" src="<?php echo __PUBLIC__;?>/validate/jquery.validate.min.js"></script>
	<script type="text/javascript" src="<?php echo __PUBLIC__;?>/validate/localization/messages_zh.min.js"></script>
	
</head>
<body background="../../public/img/bg4.jpg">
		<div>&nbsp;</div>
		<div>&nbsp;</div>
	<div class="container bg-info">
		<div class="col-md-12">&nbsp;</div>
		<div class="col-md-12">&nbsp;</div>
		<div class="row">
			<?php include '../nav.php'; ?>
		</div>
	</div>
	<div class="container bg-info">
		<div class="col-md-12">&nbsp;</div>
		<div class="col-md-12">&nbsp;</div>
		<div class="row">
			<form action="add.php" method="post" id="articleForm">
				<div class="col-md-12">&nbsp;</div>
				<div class="col-md-12">&nbsp;</div>
				<div class="col-md-12 text-center">
					<div class="form-group">
					<input type="hidden" name="id" value="<?php if(isset($row['id'])){ echo $row['id'];}?>">
						<div class="col-md-3">
							<label for="title">分类名称 :</label>
						</div>
						<div class="col-md-9">
							<input type="text" class="form-control" name="name" id="title" placeholder="分类名称" required="true" value="<?php if(isset($row['name'])){ echo $row['name'];}?>">
						</div>
						
						
					</div>
				</div>
				<div class="col-md-12">&nbsp;</div>
				<div class="col-md-12 text-center">
					<div  class="form-group">
						<div class="col-md-3">
							<label for="title">上级分类 :</label>
						</div>
						<div class="col-md-9">
							<select  class="form-control" name="pid" id="pid">
								<option value="0">顶级分类</option>
								<?php echo $CategoryStr; ?>
							</select>
						</div>
					</div>
				</div>
				<div class="col-md-12">&nbsp;</div>
				<div class="col-md-12 text-center">
					<div class="form-group">
						<div class="col-md-3">
							<label for="keyword">关 键 词 :</label>
						</div>
						<div class="col-md-9">
							<input type="text" class="form-control" name="keyword" id="keyword" placeholder="关键词" required="true" value="<?php if(isset($row['keyword'])){ echo $row['keyword'];}?>">
						</div>
					</div>
				</div>
				<div class="col-md-12">&nbsp;</div>
				<div class="col-md-12 text-center">
					<div class="form-group">
						<div class="col-md-3">
							<label for="description">描　　述 :</label>
						</div>
						<div class="col-md-9">
							<input type="text" class="form-control" name="description" id="description" placeholder="描述" required="true" value="<?php if(isset($row['description'])){ echo $row['description'];}?>">
						</div>
					</div>
				</div>
				<div class="col-md-12">&nbsp;</div>
				<div class="col-md-12 text-center">
					<div class="form-group">
						<div class="col-md-3">
							<label for="status"> 状　　态 :</label><br>
						</div>
						<div class="col-md-4 text-left">
							<select name="status">
								<?php if (!empty($row['status'])&&$row['status']==1) { ?>
									<option value="1" selected="selected">打开</option>
									<option value="0">关闭</option>
								<?php }else{ ?>
									<option value="1">打开</option>
									<option value="0" selected="selected">关闭</option>
								<?php }?>
							</select>
						</div>
						
						
					</div>
				</div>
				<div class="col-md-12">&nbsp;</div>
				<div class="col-md-12">
					<div class="form-group">
						<div class="col-md-4 text-right">
							<button class="btn btn-success" type="submit">保　　存</button>
						</div>
						<div class="col-md-4"></div>
						<div class="col-md-4">
							<button class="btn btn-success" type="reset">重　　置</button>
						</div>
					</div>
				</div>
			</form>
			<!-- 提示弹窗 -->
			<div class="modal fade bs-example-modal-sm" id="myModal" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel">
			    <div class="modal-dialog modal-sm" role="document">
			      <div class="modal-content">

			        <div class="modal-header">
			          <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
			          <h4 class="modal-title" id="mySmallModalLabel">Small modal</h4>
			        </div>
			        <div class="modal-body">
			          ...
			        </div>
			      </div>
			    </div>
			</div>
			<!-- AJAX表单提交 -->

			<script type="text/javascript">
				$('#articleForm').on('submit',function(){
					$.ajax({
						type:'post',
						url:$('#articleForm').attr('action'),
						data:$('#articleForm').serialize(),
						dataType:'json',
						success:function(data){
							if(data.code=='000'){
								window.location="index.php";
							}else{
								$('#myModal .modal-body').html(data.msg);
								$('#myModal').modal({'show':true});
							}
						}
					});
					return false;
				});
			</script>
		<div class="col-md-12">&nbsp;</div>
		<div class="col-md-12">&nbsp;</div>
		</div>
	</div>
</body>
</html>